package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fhs.trans.service.impl.TransService;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysRadioConvert;
import net.learn.system.dao.SysRadioDao;
import net.learn.system.entity.SysRadioEntity;
import net.learn.system.query.SysRadioQuery;
import net.learn.system.service.SysRadioService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysRadioVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 李立志
 * @since 2022-04-01
 */
@Service
@AllArgsConstructor
public class SysRadioServiceImpl extends BaseServiceImpl<SysRadioDao, SysRadioEntity> implements SysRadioService {

    @Override
    public String addRadio(SysRadioVO vo){
        SysRadioEntity entity = SysRadioConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        baseMapper.insert(entity);
       return uuid;
    }
    @Override
    public Boolean updateRadio(SysRadioVO vo){
        SysRadioEntity entity = SysRadioConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }
    @Override
    public List<SysRadioVO> qryRadioList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<SysRadioVO> qryRadioPaper(SysRadioQuery radioQryDto) {

        return baseMapper.qryRadioPaper(radioQryDto);
    }
    @Override
    public List<SysRadioVO> qryRadioPaperList(SysRadioQuery radioQryDto) {

        return baseMapper.qryRadioPaperList(radioQryDto);
    }

    @Override
    public List<SysRadioVO> qryRadioRandList(SysRadioQuery qry) {

        return baseMapper.qryRadioRandList(qry);
    }
    @Override
    public PageResult<SysRadioVO> qryRadioListPage(SysRadioQuery query) {
        IPage<SysRadioEntity> page = baseMapper.qryRadioListPage(getPage(query), query);

        return new PageResult<>(SysRadioConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
    @Override
    public PageResult<SysRadioVO> qryQuestionRadio(SysRadioQuery query) {

        IPage<SysRadioEntity> page = baseMapper.qryQuestionRadio(getPage(query), query);

        return new PageResult<>(SysRadioConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
    @Override
    public PageResult<SysRadioVO> qryQuestionList(SysRadioQuery query) {
        IPage<SysRadioEntity> page = baseMapper.qryQuestionList(getPage(query), query);

        return new PageResult<>(SysRadioConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
